/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.providers;

import br.ufba.lasid.v1.jitclouds.mda.MDA;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.virtualization.BasicNode;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.virtualization.IHypervisor;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.virtualization.INode;
import java.util.List;
import java.util.Properties;

/**
 *
 * @author aliriosa
 */
public class NodeProvider implements IProvider<INode>{

    @Override
    public INode create(Properties options) throws Exception {

        BasicNode node = new BasicNode();
        
        String idNode = MDA.BaseOptions.getProperty(MDA.NodeTag);
        String dsNode = MDA.Configuration.getString(idNode + ".description");
        
        node.setID(idNode);
        node.setDescription(dsNode);  
        
        List hypervisorsID = MDA.Configuration.getList(idNode + ".hypervisor.id");
        
        MDA.debug("Loading the hypervisors of node " + node.getID() + "...");
        
        for(Object hypervisorID : hypervisorsID){
            
            MDA.BaseOptions.setProperty(MDA.HypervisorTag, (String)hypervisorID);
            
            IHypervisor hypervisor = MDA.createHypervisor(options);            
            
            node.addHypervisor(hypervisor.getID(), hypervisor);
            
        }

        MDA.debug(node.getHypervisors().size() + " hypervisor(s) were loaded in " + node.getID() + "."); 
        MDA.debug("The node " + node.getID() + "[" + node.getDescription() + "] has been successfully loaded.");                    
        
        
        return node;
    }
    
}
